package cn.com.api.controller;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.service.ApiT_recommend_couponService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "recommend/")
public class ApiT_recommend_couponController {

	private static Logger logger = Logger.getLogger(ApiT_recommend_couponController.class);
	
	@Autowired
	private ApiT_recommend_couponService apiT_recommend_couponService;
	
	@RequestMapping(value = "receiveCoupons")
	public void receiveCoupons(HttpServletRequest request,
			HttpServletResponse response) throws Exception{
		/**
		 * 推荐有奖
		 * 点击领取优惠券   参数：recommend_mobile current_mobile
		 */
		Map<String, Object> map = new HashMap<String, Object>();
		try{
			String recommend_mobile = request.getParameter("recommend_mobile");
			String current_mobile = request.getParameter("current_mobile");
			String city_id = request.getParameter("city_id");
			String act_type = request.getParameter("act_type");
			Map<String, String> params = new HashMap<String, String>();
			params.put("recommend_mobile", recommend_mobile);
			params.put("current_mobile", current_mobile);
			params.put("act_type", act_type);
			params.put("city_id", city_id);
			if(apiT_recommend_couponService.checkCurrentMobile(params, map)){
				apiT_recommend_couponService.receiveCoupons(params, map);
			}
			
		}catch(Exception e){
			e.printStackTrace();
			logger.error(Util.getStackTraceAsString(e));
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.write(JsonUtil.object2json(map));
		out.close();
	}
}
